﻿/*常客预定记录和常客报表
 * 
 */
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Text;
using EZCRS.HCMS.Bll.baseinfo;
using EZCRS.HCMS.Bll;

namespace EZCRS.HCMS.myajax
{
    public class HotelOrGroup:MainBase
    {
        ArrayList arrRecord;
        //记录数量
        int iRecordCount = 0;
        //总页数
        int iPageCount = 0;

        /// <summary>
        /// 获得集团列表
        /// </summary>
        /// <param name="parentid"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string GroupAll(string parentid)
        {
            int i = 0;
            DataTable dt = new BllHotelUtil().Group_List(Convert.ToInt32(parentid));
            StringBuilder strTable = new StringBuilder();
            strTable.Append("<table id=\"tlist\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\"><tr class=\"title1\" height=\"26\"><td width=\"10%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrNumb+"</td><td width=\"70%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrGroupName+"</td><td width=\"10%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrModify+"</td><td width=\"10%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrRank+"</td></tr>");
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    strTable.Append("<tr");
                    if (i % 2 == 0)
                    {
                        strTable.Append(" class='line-odd'");
                    }
                    else
                    {
                        strTable.Append(" class='line-even'");
                    }
                    strTable.Append(" onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#B9CEEA';\"");
                    strTable.Append(" onmouseout=\"this.style.backgroundColor=currentcolor;\"");
                    strTable.Append(">");
                    strTable.Append("<td align=\"center\">");
                    strTable.Append(dr["classid"].ToString());
                    strTable.Append("</td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append("<a href=\"?id="+dr["classid"].ToString()+"\">"+dr["classname"].ToString()+"</a>");
                    strTable.Append("</div></td>");

                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append("<a href=\"group_add.aspx?id=" + dr["classid"].ToString() + "\"><img src=\"../../Image/modify.gif\" border=\"0\"/></a>");
                    strTable.Append("</div></td>");
                    strTable.Append("<td align=\"center\">");
                    if (i > 0 && dt.Rows.Count > i + 1)
                        strTable.Append("<img src=\"../../image/uparrow.png\" style=\"cursor:hand;\" onclick=\"javascript:goUp(this,3);\"><img src=\"../../image/downarrow.png\"  style=\"cursor:hand;margin-left:10px;\" onclick=\"javascript:goDown(this,3);\">");
                    else if (i == dt.Rows.Count-1)
                        strTable.Append("<img src=\"../../image/uparrow.png\" style=\"cursor:hand;margin-right:22px\" onclick=\"javascript:goUp(this,3);\">");
                    else if(i==0)
                        strTable.Append("<img src=\"../../image/downarrow.png\"  style=\"cursor:hand;margin-left:22px;\" onclick=\"javascript:goDown(this,3);\">");
                    strTable.Append("</td>");
                    strTable.Append("</tr>");
                    i++;
                }
            }
            else
            {
                strTable.Append("<tr height=\"35\" class=\"line-odd\"><td colspan=\"4\" align=\"center\">"+EZCRS.HCMS.myajax.Site.StrNonData+"</td></tr>");
            }
            strTable.Append("</table>");
            return strTable.ToString();
        }

        /// <summary>
        /// 保存排序
        /// </summary>
        /// <param name="classidlist"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string GroupSaveSort(string classidlist)
        {
            classidlist = CFun.getidlist(classidlist);
            if (new BllHotelUtil().Group_SaveSort(classidlist))
                return "1";
            else
                return "0";
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public ArrayList HotelAll(int cpage, string search)
        {
            #region
            arrRecord = new ArrayList();

            string[] str = search.Split('|');
            string gid = BasGroupId.ToString();
            int pageindex = cpage;
            DataSet ds = null;

            if (str.Length == 4)
            {
                if (str[3] == "0")
                    gid = "0";
                ds=new BllHotelUtil().Hotel_List(cpage,str[0],str[1],str[2],gid);
            }
            else
            {
                arrRecord.Add(EZCRS.HCMS.myajax.Site.StrError);
                return arrRecord;
            }

            if (ds == null)
            {
                arrRecord.Add(EZCRS.HCMS.myajax.Site.StrError);
                return arrRecord;
            }


            DataTable dt = ds.Tables[0];
            iRecordCount = Convert.ToInt32(ds.Tables[1].Rows[0][0].ToString());

            iPageCount = (iRecordCount / CFun.PageSize);
            if (iRecordCount % CFun.PageSize > 0)
            {
                iPageCount++;
            }

            //组合字符串

            StringBuilder strTable = new StringBuilder();
            #region
            strTable.Append("<table id=\"tlist\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\"><tr class=\"title1\" height=\"26\"><td width=\"5%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrNumb+"</td><td width=\"20%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrHotelName+"</td><td width=\"10%\" style=\"color: white;\">PID</td><td width=\"10%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrContact+"</td><td width=\"10%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrTel+"</td><td width=\"20%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrAddress+"</td><td width=\"1%\" style=\"color: white;\"><input type=\"checkbox\" onclick=\"javascript:clientselect(this);\"/></td></tr>");
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int row = 0; row < dt.Rows.Count; row++)
                {
                    strTable.Append("<tr");
                    if (row % 2 == 0)
                    {
                        strTable.Append(" class='line-odd'");
                    }
                    else
                    {
                        strTable.Append(" class='line-even'");
                    }
                    strTable.Append(" onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#B9CEEA';\"");
                    strTable.Append(" onmouseout=\"this.style.backgroundColor=currentcolor;\"");
                    strTable.Append(">");
                    string sNo = "";
                    if (((pageindex - 1) * CFun.PageSize + row + 1) < 10)
                    {
                        sNo = "0" + Convert.ToString(row + 1);
                    }
                    else
                    {
                        sNo = Convert.ToString((pageindex - 1) * CFun.PageSize + row + 1);
                    }
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(sNo.ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["title"].ToString());
                    strTable.Append("</div></td>");

                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["pid"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["contact_name"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["phone"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["address1"].ToString());
                    strTable.Append("<td align=\"center\"><input type=\"checkbox\" name=\"cbx\" value=\"" + ds.Tables[0].Rows[row]["pid"].ToString() + "\"/></td>");
                    strTable.Append("</tr>");
                }
            }
            else
            {
                strTable.Append("<tr height=\"35\" class=\"line-odd\"><td colspan=\"7\" align=\"center\">"+EZCRS.HCMS.myajax.Site.StrNonData+"</td></tr>");
            }
            strTable.Append("</table>");
            #endregion
            //将表格放入arraylist
            arrRecord.Add(strTable.ToString());
            //将总页数放入arraylist
            arrRecord.Add(iPageCount.ToString() == "0" ? "1" : iPageCount.ToString());
            //将总记录数放入arraylist
            arrRecord.Add(iRecordCount.ToString());

            return arrRecord;
            #endregion
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public ArrayList HotelAlone(int cpage, string search)
        {
            #region
            arrRecord = new ArrayList();

            string[] str = search.Split('|');
            
            int pageindex = cpage;
            DataSet ds = null;

            if (str.Length == 3)
            {
                ds = new BllHotelUtil().Hotel_List(cpage, str[0], str[1], str[2]);
            }
            else
            {
                arrRecord.Add(EZCRS.HCMS.myajax.Site.StrError);
                return arrRecord;
            }

            if (ds == null)
            {
                arrRecord.Add(EZCRS.HCMS.myajax.Site.StrError);
                return arrRecord;
            }


            DataTable dt = ds.Tables[0];
            iRecordCount = Convert.ToInt32(ds.Tables[1].Rows[0][0].ToString());

            iPageCount = (iRecordCount / CFun.PageSize);
            if (iRecordCount % CFun.PageSize > 0)
            {
                iPageCount++;
            }

            //组合字符串

            StringBuilder strTable = new StringBuilder();
            #region
            strTable.Append("<table id=\"tlist\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\"><tr class=\"title1\" height=\"26\"><td width=\"5%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrNumb+"</td><td width=\"20%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrHotelName+"</td><td width=\"10%\" style=\"color: white;\">PID</td><td width=\"10%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrContact+"</td><td width=\"10%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrTel+"</td><td width=\"20%\" style=\"color: white;\">"+EZCRS.HCMS.myajax.Site.StrAddress+"</td><td width=\"1%\" style=\"color: white;\"><input type=\"checkbox\" onclick=\"javascript:clientselect(this);\"/></td></tr>");
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int row = 0; row < dt.Rows.Count; row++)
                {
                    strTable.Append("<tr");
                    if (row % 2 == 0)
                    {
                        strTable.Append(" class='line-odd'");
                    }
                    else
                    {
                        strTable.Append(" class='line-even'");
                    }
                    strTable.Append(" onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#B9CEEA';\"");
                    strTable.Append(" onmouseout=\"this.style.backgroundColor=currentcolor;\"");
                    strTable.Append(">");
                    string sNo = "";
                    if (((pageindex - 1) * CFun.PageSize + row + 1) < 10)
                    {
                        sNo = "0" + Convert.ToString(row + 1);
                    }
                    else
                    {
                        sNo = Convert.ToString((pageindex - 1) * CFun.PageSize + row + 1);
                    }
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(sNo.ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["title"].ToString());
                    strTable.Append("</div></td>");

                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["pid"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["contact_name"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["phone"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["address1"].ToString());
                    strTable.Append("<td align=\"center\"><input type=\"checkbox\" name=\"cbx\" value=\"" + ds.Tables[0].Rows[row]["pid"].ToString() + "\"/></td>");
                    strTable.Append("</tr>");
                }
            }
            else
            {
                strTable.Append("<tr height=\"35\" class=\"line-odd\"><td colspan=\"7\" align=\"center\">"+EZCRS.HCMS.myajax.Site.StrNonData+"</td></tr>");
            }
            strTable.Append("</table>");
            #endregion
            //将表格放入arraylist
            arrRecord.Add(strTable.ToString());
            //将总页数放入arraylist
            arrRecord.Add(iPageCount.ToString() == "0" ? "1" : iPageCount.ToString());
            //将总记录数放入arraylist
            arrRecord.Add(iRecordCount.ToString());

            return arrRecord;
            #endregion
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string AddInfoGroup(string pidlist)
        {
            string gid = BasGroupId.ToString();
            if (gid == "0")
                return "0";
            if (new BllHotelUtil().addintogroup(pidlist, gid))
                return "1";
            else
                return "0";
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string RemoveFromGroup(string pidlist)
        {
            string gid = BasGroupId.ToString();
            if (gid == "0")
                return "0";
            if (new BllHotelUtil().removefromgroup(pidlist, gid))
                return "1";
            else
                return "0";
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string DeleteHotel(string pidlist)
        {
            if (new BllHotelUtil().Hotel_Del(pidlist))
                return "1";
            else
                return "0";
        }



    }
}
